var tableData = {
	url : ctp + "/exitSettlementController/exitSettlementSearch.shtml?workerId=" + workerId,
	hidden : [ "workhours=WORKHOURS", "workquantity=WORKQUANTITY", "shouldgive=SHOULDGIVE", "realgive=REALGIVE", "nogive=NOGIVE", "workerstate=WORKER_STATE" ],
	propertys : [ "NAME","JOBNO","GROUPNAME","SALARY","CHARGETYPE","UNITPAY","PAYFORM","WORKHOURS","WORKQUANTITY","SHOULDGIVE","REALGIVE","NOGIVE","WORKER_STATE_CHAR"],
	opers : false,
	checkBox:["REC_ID",true],
	doInput : ["REC_ID", "NOGIVE"],
	selff : hideTd,
	startLoad : function() {
		getListData(this);
	}
};
function searchData(curr) {
	setTagAndValue("form1", "curr", curr);
	setTagAndValue("form1","SUNNADA_PAGE_SIZE",100); 
	tableData.startLoad();
}
$(document).ready(function() {
	$("#applyTime").val(new Date().Format("yyyy-MM-dd hh:mm:ss"));
	$("#endDate").val(setEndDate());
	searchData();
	$('table tr').find('td:eq(1)').hide();
});

function exitpayApply(){
	if(workerId == "" || workerId == null){
		jalert("你未选择发放工资的员工，请选择！");
		return;
	}
	var nogiveArray = [];
	var workerIds = workerId.split(",");
	for(var i = 0; i < workerIds.length; i++){
		var nogiveValue = $("#NOGIVE" + workerIds[i]).val();
		if(nogiveValue == ""){
			jalert("存在员工未发工资为空的情况，请确认！");
			return;
		}else{
			var reg=/^((\-)(\d+))|(\d+)(\.\d{2})?$/ ;  
			if(!reg.test(nogiveValue)){    
				jalert("你输入的员工未发工资格式不正确，请确认！");
				return;
			}
		}
		nogiveArray.push(nogiveValue);
	}
	
	var recIds = workerId;
	var workhours = getCheckIds(null, "workhours");
	var workquantity = getCheckIds(null, "workquantity");
	var shouldgive = getCheckIds(null, "shouldgive");
	var realgive = getCheckIds(null, "realgive");
	var nogive = nogiveArray.join(",");
	var applyCode = getTimeBusiflow();
	$.ajax({ 
	 	url: ctp + "/exitSettlementController/exitpayApply.shtml",
	 	data: {"recIds": recIds, "totalTime": workhours, "totalPiece": workquantity, "totalShouldPay": shouldgive, "totalRealPay": realgive, "totalNotPay": nogive, "applyCode":applyCode},
		type : 'POST',
		success : function(result) {
			if(result == ''){
				parent.searchData();
				parent.promptInfo();
				var attendance_index = parent.layui.layer.getFrameIndex(window.name);
				parent.layui.layer.close(attendance_index);
			}else{
				jalert(result);
			}
		}
	});
}

function setEndDate(){
	var d = new Date();
	d.setTime(d.getTime()-24*60*60*1000);
	var year = d.getFullYear() + "";
	var month = d.getMonth() + 1;
	if(month < 10) month = "0" + month;
	var day = d.getDate();
	if(day < 10) day = "0" + day;
	return year + "-" + month + "-" + day;
}

function hideTd(data){
	$("[name = checkId]:checkbox").prop("checked", true);
	$('table tr').find('td:eq(0)').hide();
}